using System;
using System.Windows.Forms;
using Krile.Cores;
using Office2007Renderer;

namespace Krile.Subsystem
{
    /// <summary>
    /// Set global props
    /// </summary>
    static class SetGlobal
    {
        /// <summary>
        /// Set toolstrip renderer
        /// </summary>
        static internal void SetRenderer()
        {
            switch (Core.Config.Appearance.ToolStripDesign)
            {
                case Config._Appearance.ToolStripDesigns.Blue:
                    ToolStripManager.Renderer = new Office2007Renderer.Office2007Renderer(new Office2007BlueColorTable());
                    break;
                case Config._Appearance.ToolStripDesigns.Black:
                    ToolStripManager.Renderer = new Office2007Renderer.Office2007Renderer(new Office2007BlackColorTable());
                    break;
                case Config._Appearance.ToolStripDesigns.Silver:
                    ToolStripManager.Renderer = new Office2007Renderer.Office2007Renderer(new Office2007SilverColorTable());
                    break;
                case Config._Appearance.ToolStripDesigns.Professional:
                    ToolStripManager.Renderer = new ToolStripProfessionalRenderer();
                    break;
                default:
                    ToolStripManager.Renderer = new ToolStripSystemRenderer();
                    break;
            }
        }

        static internal void SetDefaultSearchDatas()
        {
            Core.StatusManager.RegistNewSearchData(typeof(Data.AllSearchData));
            Core.StatusManager.RegistNewSearchData(typeof(Data.TextSearchData));
            Core.StatusManager.RegistNewSearchData(typeof(Data.UserSearchData));
            Core.StatusManager.RegistNewSearchData(typeof(Data.UserIdSearchData));
            Core.StatusManager.RegistNewSearchData(typeof(Data.UserInfoSearchData));
            Core.StatusManager.RegistNewSearchData(typeof(Data.ServiceSearchData));
            Core.StatusManager.RegistNewSearchData(typeof(Data.ReplyTextSearchData));
            Core.StatusManager.RegistNewSearchData(typeof(Data.ReplyUserIdSearchData));
            Core.StatusManager.RegistNewSearchData(typeof(Data.ReplyUserSearchData));
            Core.StatusManager.RegistNewSearchData(typeof(Data.FollowingSearchData));
            Core.StatusManager.RegistNewSearchData(typeof(Data.MentionsSearchData));
            Core.StatusManager.RegistNewSearchData(typeof(Data.FavoredSearchData));
        }

        static internal void SetDefaultKeyAssigns()
        {
            sAddACM("SelectAbove");
            sAddACM("SelectBelow");
            sAddACM("SelectNewAbove");
            sAddACM("SelectNewBelow");
            sAddACM("SelectNewestStatus");
            sAddACM("DeselectTimeline");
            sAddACM("EnsureVisibleSelectedStatus");
            sAddACM("EnsureVisibleTop");
            sAddACM("JumpInReplyTo");

            sAddACM("ScrollAbove");
            sAddACM("ScrollBelow");
            sAddACM("ScrollEnd");
            sAddACM("ScrollTop");

            sAddACM("DefaultReply");
            sAddACM("DefaultFav");

            sAddACM("AddNewTab");
            sAddACM("AddQuickTab");
            sAddACM("EditSelectedTab");
            sAddACM("CloseSelectedTab");
            sAddACM("RestoreClosedTab");
            sAddACM("ExtractThisUser");
            sAddACM("ExtractThisUserStrict");
            sAddACM("ExtractThisService");
            sAddACM("ExtractThisPostsReply");
            sAddACM("ExtractConversation");


            sAddACM("SelectLeftTab");
            sAddACM("SelectRightTab");
            sAddACM("Select1stTab");
            sAddACM("Select2ndTab");
            sAddACM("Select3rdTab");
            sAddACM("Select4thTab");
            sAddACM("Select5thTab");
            sAddACM("Select6thTab");
            sAddACM("Select7thTab");
            sAddACM("Select8thTab");
            sAddACM("Select9thTab");
            sAddACM("Select10thTab");
            sAddACM("Select11thTab");
            sAddACM("Select12thTab");

            sAddACM("NextWindow");
            sAddACM("PrevWindow");

            sAddACM("FocusToTimeline");
            sAddACM("OpenPostbox");
            sAddACM("ClosePostbox");
            sAddACM("TogglePostbox");

            sAddACM("OpenSearchBar");
            sAddACM("CloseSearchBar");
            sAddACM("ToggleSearchBar");

            sAddACM("SetAlreadyReadedAll");
            sAddACM("RefreshTimeline");

            sAddACM("ShowConfig");
            sAddACM("ShowStatusPage");
            sAddACM("ShowUserPage");

            sAddACM("CopyStatus");
            sAddACM("CopyUserID");

            sAddACM("SetGlobalTL");
            sAddACM("ToggleUnlock");
            sAddACM("ToggleTopmost");

            sAddACM("RestartKrile");
            sAddACM("KillKrile");
        }

        static private void sAddACM(string candidate)
        {
            var delg = System.Delegate.CreateDelegate(
                    typeof(Krile.Kernel.Data.Common.KeyAssignCallback),
                    typeof(Data.DefaultKeyAssigns),
                    candidate) as Krile.Kernel.Data.Common.KeyAssignCallback;
            if (delg == null)
                throw new InvalidOperationException();
            Core.KeyAssign.AddAssignCandidateMethod(
                delg,
                Lang.KeyAssign.ResourceManager.GetString(candidate));
        }
    }
}
